package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.changeModelPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:changeModel
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/17 14:49
 * @Version 1.0
 */
@Mapper
public interface changeModelMapp {
    //插入一行新的数据
    @DS("baodingRussia")
    @Insert("insert into change_model (workshop, lineName," +
            " op, fileName, editionNum," +
            " writeDate, executeDate, fileNum," +
            " writeUse, examineUse, ratifyUse," +
            " countersignUse, workBook, bookImage," +
            " bookVideo, editRecord, bookType," +
            "deleteSign, establishTime, UpdateTime)" +
            " VALUES (#{workshop},#{lineName}," +
            "#{op},#{fileName},#{editionNum}," +
            "#{writeDate},#{executeDate},#{fileNum}," +
            "#{writeUse},#{examineUse},#{ratifyUse}," +
            "#{countersignUse},#{workBook},#{bookImage}," +
            "#{bookVideo},#{editRecord},#{bookType}," +
            "#{deleteSign}, #{establishTime},#{UpdateTime})")
    void insertOne(changeModelPojo changModel);
    //根据一个字段，查询所有的数据，使用字符串类的
    @DS("baodingRussia")
    @Select("select * from change_model where ${filedName}=#{filedVal} and deleteSign=1")
    List<changeModelPojo> inquiryByOneField(String filedName, String filedVal);
    //修改一行的表头数据
    @DS("baodingRussia")
    @Update("update change_model set " +
            "workshop=#{workshop}," +
            "lineName=#{lineName}," +
            "op=#{op}," +
            "editionNum=#{editionNum}," +
            "fileName=#{fileName}," +
            "writeDate=#{writeDate}," +
            "executeDate=#{executeDate}," +
            "writeUse=#{writeUse}," +
            "examineUse=#{examineUse}," +
            "ratifyUse=#{ratifyUse}," +
            "countersignUse=#{countersignUse} " +
            "where id=#{id}")
    void editChangeModelTable(changeModelPojo changeModel);
    //修改一个int类型的字段，现在用在修改标记位上
    @DS("baodingRussia")
    @Update("update change_model set ${fieldName}=#{fieldVal} where id=#{id}")
    void editFielDInt(Integer id, String fieldName, int fieldVal);
    //修改一个字符串类型的字段，现在用在修改作业指导书上，同时也传来了旧的内容，作为修改修改记录用,同时修改了编制时间
    @DS("baodingRussia")
    @Update("update change_model set ${fieldName}=#{fieldVal},editRecord=#{editRecord},UpdateTime=#{update} where id=#{id}")
    void editChangeModelField(Integer id, String fieldName, String fieldVal, String editRecord, String formattedDate, LocalDateTime update);
    //根据传来的字段名，修改字段（在新页面中也应用了）
    @DS("baodingRussia")
    @Update("update change_model set ${fieldName}=#{fileNameAll},UpdateTime=#{dateTime} where id=#{id}")
    void editFieldOneById(Integer id, String fieldName, String fileNameAll, LocalDateTime dateTime);
    //删除图片的数据库内容
    @DS("baodingRussia")
    @Update("update change_model set ${fieldName}=#{fieldValue} ,UpdateTime=#{dateTime} where id=#{id}")
    void delPointOneField(Integer id, String fieldName, String filedValue, LocalDateTime dateTime);
    //删除图片的，修改数据库
    @DS("baodingRussia")
    @Update("update change_model set ${fieldName}=#{filedVal},UpdateTime=#{dateTime} where id=#{id}")
    void delPointOneFieldRemove(Integer id, String fieldName, String filedVal, LocalDateTime dateTime);
    //根据一个id，编辑一个字段，不需要写整行的编辑
    @DS("baodingRussia")
    @Update("update change_model set ${filedName}=#{filedVal} where id=#{id}")
    void editOneFiledById(Integer id, String filedName, String filedVal);
}
